//
//  tools.m
//  7-11快医
//
//  Created by amor on 16/7/11.
//  Copyright © 2016年 amor. All rights reserved.
//

#import "CJTTools.h"
#import <AFNetworking.h>

@interface CJTTools ()
//- (void)postURL:(NSString *)url parameter:(NSDictionary *)parameters;
@end

@implementation CJTTools

+(instancetype)shareTools{
    
    static CJTTools *tool;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        tool = [[CJTTools alloc] init];
        
    });
    
    return tool;
    
}
//- (void)postMethod{
//    
//    //    获取医生列表接口
//    NSString *url = @"http://iosapi.itcast.cn/doctor/matchDoctors.json.php";
//    NSDictionary *parameters = @{@"ci1_id":@1,@"ci2_id":@3,@"ci3_id":@3,@"diagnosis_type":@0,@"page_size":@15,@"is_confirmed":@1,@"user_id":@1000089, @"page":@1,@"has_diagnosis":@2};
//    
//    [self postURL:url parameter:parameters];
//    
//}

+ (void)postURL:(NSString *)url parameter:(NSDictionary *)parameters result:(void(^)(id responseObject,NSError *error))result {
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //需要json请求
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    //需要设置返回值类型修改
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",nil];
    [manager POST:url parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSLog(@"responseObject = %@",responseObject);
        // 成功
        result(responseObject,nil);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error = %@",error);
        result(nil, error);
    }];
    
}

@end
